package online.heycm.platform.log;

import online.heycm.platform.common.entity.constant.Constant;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author hey
 * @version 1.0
 * @date 2023/12/27 9:38
 */
public class LoggerManager {

    private static final Map<String, Logger> LOGGER_CACHE = new ConcurrentHashMap<>();

    public static Logger getLogger(Class<?> clazz) {
        assert clazz != null;
        Logger logger = LOGGER_CACHE.get(clazz.getName());
        if (logger == null) {
            synchronized (LoggerManager.class) {
                logger = LOGGER_CACHE.get(clazz.getName());
                if (logger == null) {
                    logger = new Logger(LoggerFactory.getLogger(clazz));
                    LOGGER_CACHE.put(clazz.getName(), logger);
                }
            }
        }
        return logger;
    }

}
